<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <h1>{{msg}}</h1>
      <home-com1></home-com1>
      <home-com2></home-com2>
    </div>

    <div id="app2">
      <h1>app2</h1>
      <newcom1></newcom1>
      <newcom2></newcom2>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script>
      var vm = new Vue({
        el: "#app",
        data: {
          msg: "vue",
        },
        methods: {

        },
        //局部组件
        components: {
          "home-com1": {
            data(){
              return  {
                msg:'home-com1'
              }
            },
            template:"<div>{{msg}}</div>"
          },
          "home-com2":{
            data(){
              return {
                msg2:'home-com2'
              }
            },
            template :'<div>{{msg2}}</div>'
          }
        },
      });

      //组件1注册
      let newcom1 = {
        data(){
          return {
            msg:'美国 队长'
          }
        },
        template:'<div>{{msg}}</div>'
      }

      // 组件2注册
      let newcom2 = {
        data(){
          return {
            msg:'绯红女巫'
          }
        },
        template:"<div>{{msg}}</div>"
      }

      var vm2 = new Vue({
        el:'#app2',
        components:{
          newcom1:newcom1,
          newcom2:newcom2
        }
      })
    </script>
  </body>
</html>
